// pages/examhome/examhome.js
const App = getApp();
const {
  get,
  post
} = App.require('request/index')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    modifyList: [],
    catList: [{
      name: '训练模式',
      id: 1
    }],
    icon: 1,
    navHeight: App.globalData.navHeight,
    prolist: wx.getStorageSync('prolist') == '' ? wx.getStorageSync('prolist') : JSON.parse(wx.getStorageSync('prolist')),
    currentPage:1,
    pageSize:5000
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getmodify();
  },
  check(e) {

    this.setData({
      icon: e.currentTarget.dataset.id
    })
  },
  getmodify() {
    let {modifyList,currentPage,pageSize} = this.data
    post(`/app/exam/repository/list?currentPage=${currentPage}&pageSize=${pageSize}`, {}).then(res => {
      let list = []
      list = res.data.list
      this.setData({
        modifyList: list
      })
    })
  },
  detail(e) {
    let {
      prolist
    } = this.data;
    post('/app/exam/question/trainingMode', {
      repoId: e.currentTarget.dataset.id,
      memberId: prolist.userid
    }).then(res => {
      console.log(res);
      let str = JSON.stringify(res.data)
      wx.navigateTo({
        url: `/pages/examadmin/pages/traindetail/traindetail?data=${str}`
      })
    })


  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      currentPage: 1,
      modifyList:[]
    })
    wx.showLoading({  
      title: '刷新中...',
    })
  
    wx.hideLoading();
    wx.stopPullDownRefresh()
    this.getmodify()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () { 
     
    this.setData({
      currentPage: this.data.currentPage + 1
    })
    this.getmodify()

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})